﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="KeywordTagCloud.aspx.cs" Inherits="NewsAggregator.KeywordTagCloud" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Header" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <style>
        #tagCloud {
          width:100%; background-color:#575454; text-align:center; padding:5px;
          overflow:auto; font-size:70%; font-family:arial;
        }
        #tagCloud h2 {
          color:#ffffff; font-size:2.5em; margin:0 0 10px 0;
          background:url(images/cloud.gif) no-repeat 0; padding:15px 0 15px 80px;
        }
        #tagList { margin:0; padding:0; }
        #tagList li {
          list-style-type:none; float:left; margin:0 10px; height:35px;
        }
        #tagList li a { text-decoration:none; color:#ffffff; }
        #tagList li a:hover { text-decoration:underline; }
    </style>

    <script type="text/javascript">
        $(function () {
            GetKeywordData();
        });

        function GetKeywordData() {           
            var pageUrl = '<%=ResolveUrl("~/WebService/KeyCloud.asmx")%>';
            var li = "";

            $.ajax({
                type: "POST",
                url: pageUrl + "/GetKeyWords",
                data: "",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (results) {
                    //create list for tag links
                    $("<ul>").attr("id", "tagList").appendTo("#tagCloud");                    
                    //alert(results.d);
                    var keywordCounts = JSON.parse(results.d);
                    var max = min = 0;
                    var min_rad = 8;
                    var max_rad = 20;
                    $.each(keywordCounts, function (i) {
                        max = (max > keywordCounts[i].keycount) ? max : keywordCounts[i].keycount;
                        //min = (min < keywordCounts[i].keycount) ? min : keywordCounts[i].keycount;
                    });

                    $.each(keywordCounts, function (i) {
                       
                       // alert(keywordCounts[i].KeyID);
                        //create item
                        li = $("<li>");

                        //create link
                        $("<a>").text(keywordCounts[i].KeyID).attr({ title: keywordCounts[i].KeyID, href: "SearchView.aspx?key=" + keywordCounts[i].KeyID }).appendTo(li);

                        var n = Math.ceil(min_rad + (max_rad - min_rad) * (keywordCounts[i].keycount - 1) / (max - 1));

                        //set tag size
                        li.children().css("fontSize", n);

                        //add to list
                        li.appendTo("#tagList");

                    });
                }
            });
        }
    </script>

    <div id="tagCloud"></div>

</asp:Content>
